package org.hackystat.devcathlon.ui.page.scoreboard;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.hackystat.devcathlon.engine.match.Match;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.DevcathlonBasePage;
import org.hackystat.devcathlon.ui.page.matches.MatchesSession;
import org.hackystat.devcathlon.ui.page.scoreboard.commentpanel.FrontCommentPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.eventspanel.FrontEventsPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.gameinfopanel.FrontInfoPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.logopanel.LogoPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.performerpanel.FrontPerformerPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.scorespanel.ScoresPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.teamleftpanel.FrontTeamLeftPanel;
import org.hackystat.devcathlon.ui.page.scoreboard.teamrightpanel.FrontTeamRightPanel;

/**
 * Implements the top-level Scoreboard page, which provides a summary of recent 
 * occurrences in Devcathlon.
 * 
 * @author Daniel Arakaki, John Ancheta
 *
 */
public class ScoreboardPage extends DevcathlonBasePage implements Serializable {
  
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  
  /**
   * Creates the Scoreboard page.  
   * This page and its subpages contain information about this specific user.  
   */
  public ScoreboardPage ()  {
    // Set the body class attribute to section-1 so that the menubar is correct.
    add(new WebMarkupContainer("body") { 
      private static final long serialVersionUID = 1L;
      @Override
      public boolean isTransparentResolver() { 
        return true; 
        } 
      @Override
      protected void onComponentTag(ComponentTag tag) { 
        tag.put("class", "thrColElsHdr section-4"); 
        }
    }
    );
    
    DevcathlonSession devcathlonSession = DevcathlonSession.get();
    MatchesSession matchesSession = devcathlonSession.getMatchesSession();
    
    List<Match> listOfMatches = new ArrayList<Match>(matchesSession.getUserMatches());
    
    // Make the tab corresponding to this page bold.
    get("ScoreboardLink").add(new SimpleAttributeModifier("class", "selected"));
    
    add(new ScoresPanel("scores_panel", matchesSession.getMatchNames()));
    add(new FrontTeamLeftPanel("frontteamleft_panel", matchesSession.getMatchNames()));
    add(new LogoPanel("frontlogo_panel", matchesSession.getMatchNames()));
    add(new FrontInfoPanel("frontinfo_panel", listOfMatches));
    add(new FrontTeamRightPanel("frontteamright_panel", matchesSession.getMatchNames()));
    add(new FrontEventsPanel("frontevents_panel", matchesSession.getMatchNames()));
    add(new FrontCommentPanel("comment_panel", listOfMatches));
    add(new FrontPerformerPanel("frontperformer_panel", matchesSession.getMatchNames())); 
  }
 
}

